 /* 
 * File:   cItem.cpp
 * Author: josep
 * 
 * Created on 30 / desembre / 2010, 18:40
 */

#include "cItem.h"

cItem::cItem() {
    this->ObjetctType=ITEM_OBJECT_TYPE;
    this->TexCoord[0][0]=0;
    this->TexCoord[0][1]=0;
    this->TexCoord[1][0]=1;
    this->TexCoord[1][1]=1;
}
void cItem::SetObjectIndex(int ObjectIndex) {
    this->ObjectIndex = ObjectIndex;
}
int cItem::GetObjectIndex() const {
    return ObjectIndex;
}
void cItem::SetValue(int value) {
    this->value = value;
}
int cItem::GetValue() const {
    return value;
}

cItem::cItem(const cItem& orig):cPositionedVisibleObject(orig) {
    value=orig.value;
    ObjectIndex=orig.ObjectIndex;
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
                TexCoord[i][j]=orig.TexCoord[i][j];
        }
    }
}

cItem::~cItem() {
}

void cItem::Init(cTexture *texture, int PosX, int PosY, int ObjecyIndex,
                                int value, int Width, int Height){
    cPositionedVisibleObject::Init(texture, PosX, PosY, Width, Height);
    this->ObjectIndex=ObjecyIndex;
    this->value=value;

}
void cItem::Captured(){
    this->NoMoreTime();
}

void cItem::Draw(){
    float ratio[2]={TexCoord[1][X]-TexCoord[0][X], TexCoord[1][Y]-TexCoord[0][Y]};
    cTexture *Texture;
    Texture = GetTexture();
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, Texture->GetID());
    glBegin(GL_QUADS);
        glTexCoord2f(TexCoord[0][X], TexCoord[0][Y]);
        glVertex2i(GetPosX() , GetPosY() + GetTextureHeight()*ratio[Y]);

        glTexCoord2f(TexCoord[1][X],TexCoord[0][Y]);
        glVertex2i(GetPosX() + GetTextureWidth()*ratio[X],
                        GetPosY() + GetTextureHeight()*ratio[Y]);

        glTexCoord2f(TexCoord[1][X], TexCoord[1][Y]);
        glVertex2i(GetPosX() + GetTextureWidth()*ratio[X],GetPosY());

        glTexCoord2f(TexCoord[0][X], TexCoord[1][Y]);
        glVertex2i(GetPosX(), GetPosY());
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

void cItem::SetTextCoord(int coorId, int Dir, float value){
    TexCoord[coorId][Dir]=value;
}

float cItem::GetTextCoord(int coorId, int Dir){
    return TexCoord[coorId][Dir];
}


